package socket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

public class SocketClient {

	static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		Socket socket = new Socket(InetAddress.getLocalHost(), 6666);
		BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
		while (true) {
			System.out.println("Client端请输入：");
			String str = scanner.next();
			pw.println(str);
			pw.flush();
			String string = br.readLine();
			System.out.println("Client读到：" + string);
			if (str.equals("exit")) {
				break;
			}
		}
		socket.close();
	}

}
